class AllowedWebsitesController < ApplicationController

    layout 'default'
    
    before_filter :login_required
    before_filter :setup_user
            
    def index
        list
        render :action => 'list'
    end

    # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
    verify :method => :post, :only => [ :destroy, :create, :update ],
    :redirect_to => { :action => :list }

    def list
        @allowed_website_pages, @allowed_websites = paginate :allowed_websites, :per_page => 10
    end

    def show
        @allowed_website = AllowedWebsite.find(params[:id])
    end

    def new
        @allowed_website = AllowedWebsite.new
    end

    def create
        @allowed_website = AllowedWebsite.new(params[:allowed_website])
        if @allowed_website.save
            @user.allowed_websites << @allowed_website
            flash[:notice] = 'AllowedWebsite was successfully created.'
            redirect_to :action => 'list'
        else
            render :action => 'new'
        end
    end

    def edit
        @allowed_website = AllowedWebsite.find(params[:id])
    end

    def update
        @allowed_website = AllowedWebsite.find(params[:id])
        if @allowed_website.update_attributes(params[:allowed_website])
            flash[:notice] = 'AllowedWebsite was successfully updated.'
            redirect_to :action => 'show', :id => @allowed_website
        else
            render :action => 'edit'
        end
    end

    def destroy
        AllowedWebsite.find(params[:id]).destroy
        redirect_to :action => 'list'
    end
    
    protected
    def setup_user
        #@user = User.find(params[:user_id])
        @user = current_user
    end
    
end
